﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace NetLogger
{
	public class NetFormerMember
	{
		public NetFormerMember( XElement node )
		{
			foreach ( XElement item in node.Elements() )
			{
				switch ( item.Name.LocalName )
				{
					case "roster_id":
						Callsign = NetPost.DecodedString( item );
						break;
					case "name":
						Name = NetPost.DecodedString( item );
						break;
					case "location":
						Location = NetPost.DecodedString( item );
						break;
					case "aprs_id":
						AprsId = NetPost.DecodedString( item );
						break;
					case "latitude":
						Latitude = ( double ) item;
						break;
					case "longitude":
						Longitude = ( double ) item;
						break;
				}
			}
		}

		public string Callsign
		{
			get;
			private set;
		}

		public string Name
		{
			get;
			private set;
		}

		public string Location
		{
			get;
			private set;
		}

		public string AprsId
		{
			get;
			private set;
		}

		public double Latitude
		{
			get;
			private set;
		}

		public double Longitude
		{
			get;
			private set;
		}

		public bool IsVerified
		{
			get
			{
				return Latitude != 0d && Longitude != 0d;
			}
		}

		public bool HasLocation
		{
			get
			{
				return !string.IsNullOrWhiteSpace( Location );
			}
		}

		public override bool Equals( object obj )
		{
			if ( obj is NetFormerMember )
				return ( ( NetFormerMember ) obj ).Callsign == Callsign;
			else
				return false;
		}

		public override int GetHashCode()
		{
			return Callsign.GetHashCode();
		}

		public override string ToString()
		{
			return Callsign;
		}
	}
}
